package com.Bigbluebook.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.Bigbluebook.R;
import java.util.List;

public class MyLikeAdapter extends RecyclerView.Adapter<MyLikeAdapter.MyLikeViewHolder> {

    private List<LikeItem> likeItems;

    public MyLikeAdapter(List<LikeItem> likeItems) {
        this.likeItems = likeItems;
    }

    @NonNull
    @Override
    public MyLikeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.like_item, parent, false);
        return new MyLikeViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyLikeViewHolder holder, int position) {
        LikeItem item = likeItems.get(position);
        holder.author.setText(item.getAuthor());
        holder.content.setText(item.getContent());
        holder.time.setText(item.getTime());
        // 设置头像，这里需要您自己实现获取图片资源的逻辑
        holder.avatar.setImageResource(R.mipmap.ic_launcher); // 假设使用ic_launcher作为占位符
    }

    @Override
    public int getItemCount() {
        if(likeItems==null){
            return 0;
        }
        return likeItems.size();
    }

    public static class MyLikeViewHolder extends RecyclerView.ViewHolder {
        public ImageView avatar;
        public TextView author;
        public TextView content;
        public TextView time;

        public MyLikeViewHolder(View view) {
            super(view);
            author = view.findViewById(R.id.Like_author);
            content = view.findViewById(R.id.Like_content);
            time = view.findViewById(R.id.createLikeTime);
        }
    }

    public static class LikeItem {
        private String author;
        private String content;
        private String time;

        public LikeItem(String author, String content, String time) {
            this.author = author;
            this.content = content;
            this.time = time;
        }

        public String getAuthor() {
            return author;
        }

        public String getContent() {
            return content;
        }

        public String getTime() {
            return time;
        }
    }
}
